//
//  YTNetworkManager+YiTaiNetwork.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/13.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTNetworkManager+YiTaiNetwork.h"
#import "YTHomeMainModel.h"
#import "YTHomeDetailModel.h"
#import "YTRecommedArticleModel.h"

#define kSuccCode 1

@implementation YTNetworkManager (YiTaiNetwork)


#pragma mark: - 首页banner 网络请求
- (void)requestBannerWithCompletion:(void(^)(YTHomeBanner *banner ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = @"ThemeSettings/getBannerInfo";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            // 网络有问题
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            YTHomeBanner *banner = [YTHomeBanner yy_modelWithJSON:json[@"data"]];
           
            completion(banner, true,nil);

        }else{
            completion(nil,false,json[@"msg"]);
        }
        
    }];
}

#pragma markl: - 获取快讯列表
- (void)requestNewFlashWithCompletion:(void(^)(NSArray *list ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = @"Home/getNewsFlashLists";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil completion:^(id json, BOOL isSuccess)
    {
        // 网络有问题
        if (!isSuccess) {
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSArray *list = [NSArray yy_modelArrayWithClass:[YTNewFlashModel class] json:json[@"data"][@"list"][@"lives"]];
            completion(list,true,nil);
        }else{
            
            // 失败
            completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 关注作者的 网络请求
- (void)requestFollowAuthorWithFollowID:(NSString *)followID
                               isFollow:(BOOL)isFollow
                             completion:(void(^)(BOOL isSucc,BOOL isReward, NSString *error))completion
{
    NSString *followUrl = @"Collection/addFollowUser";
    NSString *cancelUrl = @"Collection/deleFollowUser";
    
    // 是否已经关注
    NSString *url = isFollow ? cancelUrl : followUrl;
    
    NSDictionary *param = @{@"followuid":followID};
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        //NSLog(@"%@",self.account);
        if (!isSuccess) {
            completion(false,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSString *msg = isFollow ? json[@"msg"] : ([json[@"data"][@"reward"][@"is_reward"] boolValue] ? json[@"data"][@"reward"][@"money"] : json[@"msg"]);
            completion(YES,[json[@"data"][@"reward"][@"is_reward"] boolValue],msg);
        }else{
            completion(false,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 快讯首页 网络请求
- (void)requestMainNewFlashWithPage:(int)page
                             page_size:(NSString *)page_size
                            mintime:(NSString *)mintime
                       completion:(void(^)(id json ,BOOL isSucc))completion
{
    NSString *url = @"Home/getNewsFlashLists";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"page"] = @(page);
    dictM[@"page_size"] = @"10";
    //dictM[@"limit"] = @(20);
    dictM[@"mintime"] = mintime;
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess);
            return ;
        }
        
        
        completion(json,isSuccess);
    }];
}

#pragma mark: - 利空点赞接口 网络请求
- (void)postNewFlashGoodOrBadWithlid:(NSString *)lid
                                type:(NSString *)type
                          completion:(void(^)(BOOL isSucc ,NSString *statusInfo))completion
{
    NSString *url = @"GetNews/putNewsIslike";
    NSLog(@"%@",lid);
    NSDictionary *dict = @{@"lid":lid,
                           @"types":type
                           };
    
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dict
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            completion(YES,[json[@"data"][@"reward"][@"is_reward"] boolValue] ? json[@"data"][@"reward"][@"money"] : nil);
        }else{
            completion(false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 搜索接口 网络请求
- (void)requestSeachWithKeyWord:(NSString *)keyword
                          paged:(int)paged
                      page_size:(NSString *)page_size
                     completion:(void(^)(YTHomeSearchModel *model, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"Search/index";
    
    NSDictionary *param = @{@"keyword":keyword,
                            @"paged":@(paged),
                            @"page_size":page_size
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTHomeSearchModel *model = [YTHomeSearchModel yy_modelWithJSON:json[@"data"]];
            completion(model,YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 签到详情 网络请求
- (void)requestSiginWithCompletion:(void(^)(YTSiginModel *model,BOOL isSucc, NSString *StatusInfo))completion
{
    NSString *url = @"UserCenter/getSignInInfo";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTSiginModel *sign = [YTSiginModel yy_modelWithJSON:json[@"data"]];
            completion(sign,YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
}


#pragma mark: - 签到奖励类型 1每日签到 2注册 3文章阅读 4文章点赞 5文章收藏 6文章评论 7文章分享 8快讯投票 9快讯分享 网络请求
- (void)requestSiginWithType:(NSString *)type
                     post_id:(NSString *)post_id
                  completion:(void(^)(BOOL isSucc, NSString *StatusInfo))completion
{
    NSString *url = @"Com/sendUserIntegral";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"type"] = type;
    dictM[@"post_id"] = post_id;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
            
            // 签到 . 文章分享  // 文章 快讯 分享
            if ([type isEqualToString:@"1"] || [type isEqualToString:@"9"]||
                [type isEqualToString:@"7"] || [type isEqualToString:@"3"]) {
                completion(YES,json[@"data"][@"reward"][@"money"]);
                return;
            }
           
    
            completion(YES,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 热搜列表 网络请求
- (void)requestHotSearchWithCompletion:(void(^)(NSArray *list ,BOOL isSucc , NSString *error))completion
{
    NSString *url = @"Search/getHotQueryWord";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json[@"data"],YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
}


#pragma mark: - 首页文章 网络请求
- (void)requestHomeListWithTerm_id:(NSString *)term_id
                             paged:(int)page
                         page_size:(int)page_size
                        menu_order:(BOOL)menu_order
                           mintime:(NSString *)mintime
                    completion:(void(^)(YTHomeMainModel *model ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = @"Home/getNewsListAll";
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"term_id"] = term_id;
    param[@"mintime"] = mintime;
    param[@"menu_order"] = @(menu_order);
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param.copy completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode)
        {
            YTHomeMainModel *model = [YTHomeMainModel yy_modelWithJSON:json[@"data"]];
            
            completion(model,YES,nil);
            
        }else{
              completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 退出登录 网络请求
- (void)requestLogOutWithCompletion:(void(^)(BOOL isSucc, NSString *StatusInfo))completion
{
    NSString *url = @"Com/logout";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,@"退出成功");
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 文章详情网络请求
- (void)requestArticleDetailWithID:(NSString *)ID
                        completion:(void(^)(YTHomeDetailModel *model ,BOOL isSucc ,NSString *error))completion
{
    if (!self.account.accessToken) {
        [self getAccessTokeWithCompletion:^(BOOL isSucc, NSString *error) {
            if (!isSucc) {
                completion(nil,false,@"网络不给力...");
                return ;
            }
            
            NSString *url = @"Home/getNewsInfo";
            
            NSDictionary *dict = @{@"post_id":ID};
            
            [self requestWithMethod:MethodGet
                          UrlString:url
                             params:dict
                         completion:^(id json, BOOL isSuccess)
             {
                 // 网络有问题
                 if (!isSuccess) {
                     completion(nil,false,@"网络不给力...");
                     return ;
                 }
                 
                 
                 // 成功
                 if ([json[@"code"] intValue] == kSuccCode) {
                     
                     YTHomeDetailModel *model = [YTHomeDetailModel yy_modelWithJSON:json[@"data"]];
                     
                     completion(model,YES,nil);
                 }else{
                     // 失败
                     completion(nil,false,json[@"msg"]);
                 }
                 
             }];
        }];
        return;
    }else{
   
    
    
    NSString *url = @"Home/getNewsInfo";
    
    NSDictionary *dict = @{@"post_id":ID};
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dict
                 completion:^(id json, BOOL isSuccess)
    {
        // 网络有问题
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTHomeDetailModel *model = [YTHomeDetailModel yy_modelWithJSON:json[@"data"]];
            
            completion(model,YES,nil);
        }else{
            // 失败
            completion(nil,false,json[@"msg"]);
        }
      
    }];
    }
}

#pragma mark: - 热门评论 网络请求
- (void)requestHotCommentWithTid:(NSString *)tid
                           paged:(int)paged
                       page_size:(NSString *)page_size
                      completion:(void(^)(YTDHNewComment *comModel ,BOOL isSucc,NSString *error))completion
{
    NSString *url = @"CommentsInfo/getHotCommentList";
    
    NSDictionary *param = @{@"tid":tid,
                            @"paged":@(paged),
                            @"page_size":page_size
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
           // NSArray *list = [NSArray yy_modelArrayWithClass:[YTHDComment class] json:json[@"data"][@"list"]];
            YTDHNewComment *comModel = [YTDHNewComment yy_modelWithJSON:json[@"data"]];
            completion(comModel,YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
    
}
#pragma mark: - 文章详情点赞 网络请求
- (void)requestLikesArticleWithTid:(NSString *)tid
                              tuid:(NSString *)tuid
                        completion:(void(^)(BOOL isSucc, NSString *StatusInfo))completion
{
    NSString *url = @"Collection/addPostRecommend";
    
    NSDictionary *param = @{@"tid":tid,
                            @"tuid":tuid
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,[json[@"data"][@"reward"][@"is_reward"] boolValue] ? json[@"data"][@"reward"][@"money"] : nil);
        }else{
            completion(NO,@"不能取消点赞哦...");
        }
    }];
}
#pragma mark: - 文章一级评论 网络请求
- (void)requestHDCommentListWithTid:(NSString *)tid
                              paged:(int)page
                         completion:(void(^)(YTDHNewComment *model ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = @"CommentsInfo/getCommentsList";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"tid"] = tid;
    dictM[@"paged"] = @(page);
    [self requestWithMethod:MethodGet
                  UrlString:url params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTDHNewComment *model = [YTDHNewComment yy_modelWithJSON:json[@"data"]];
            completion(model,YES,nil);
        }else{
            
            completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 文章详情 评论点赞
- (void)requestDetailLikeCommentWithTid:(NSString *)tid
                                    pid:(NSString *)pid
                             completion:(void(^)(BOOL isSucc ,NSString *error))completion
{
    NSString *url = @"Collection/addCommentRecommend";
    
    NSDictionary *param = @{@"tid":tid,
                            @"pid":pid
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
       
    }];
}

#pragma mark: - 相关文章 网络请求
- (void)requestRelatArticleWithTid:(NSString *)tid
                             paged:(int)paged
                         page_size:(int)page_size
                        completion:(void(^)(NSArray *list ,BOOL isSucc, NSString *classID,NSString *error))completioon
{
    NSString *url = @"Home/getRecommendPost";
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"tid"] = tid;
    param[@"paged"] = @(paged);
    param[@"page_size"] = @(page_size);
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completioon(nil,false,nil,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSArray *list = [NSArray yy_modelArrayWithClass:[YTRecommedArticleModel class]
                                                       json:json[@"data"][@"list"]];
            completioon(list,isSuccess,json[@"data"][@"postClassId"],nil);
        }else{
            completioon(nil,false,nil,json[@"msg"]);
        }
    }];
}

#pragma mark: - 用户登录、注册 网络请求
- (void)requestLoginOrRegistWithPhone:(NSString *)phone
                                 code:(NSString *)code
                           completion:(void(^)(BOOL isSucc ,NSString *error))completion
{
    NSString *url = @"Com/loginByPhone";
    
    NSDictionary *param = @{@"phone":phone,@"code":code};
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
            NSNumber *isPass = self.account.isPass;
            NSString *accessToken = self.account.accessToken;
            
            self.account = [YTUserAccount yy_modelWithJSON:json[@"data"]];
            self.account.accessToken = accessToken;
            self.account.isPass = isPass;
            [[self requestSerializer] setValue:self.account.auth forHTTPHeaderField:@"user-token"];
            [self.account saveUserAccount];
            completion(YES,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 加载分类 网络请求
- (void)requestCatorgListWithCompletion:(void(^)(NSArray *list ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = @"ThemeSettings/getCategoryLabels";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络有问题");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSArray *list = [NSArray yy_modelArrayWithClass:[YTHomeCate class] json:json[@"data"]];
            completion(list, isSuccess,nil);
        }else{
            
            completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 更新个人信息 网络请求
- (void)postEditedMineInfoWithMeta_key:(NSString *)meta_key
                               meta_value:(NSString *)meta_value
                               completion:(void(^)(BOOL isSucc ,NSString *statusInfo))completion
{
    NSString *url = @"UserCenter/updateUserInfo";
    
    NSDictionary *param = @{@"meta_key":meta_key,
                            @"meta_value":meta_value
                            };
    
   

    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网路不给力...");
            return ;
        }

         if ([json[@"code"] intValue] == kSuccCode) {
             completion(isSuccess,json[@"msg"]);
         }else{
             completion(false,json[@"msg"]);
         }
    }];
}

#define kHistoryUrl @"UserCenter/historyList"
#define kCollectionUrl @"UserCenter/getCollectionList"
#pragma mark: - 收藏、历史列表 网络请求
- (void)requestCollectionListWithIshistory:(BOOL)isHistory
                                     paged:(int)paged
                            page_size:(int)page_size
                           completion:(void(^)(YTHomeMainModel *model ,BOOL isSuccess ,NSString *error))completion
{
    NSString *url = isHistory ? kHistoryUrl : kCollectionUrl;
    
    NSDictionary *param = @{@"paged":@(paged),
                            @"page_size":@(page_size)
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTHomeMainModel *model = [YTHomeMainModel yy_modelWithJSON:json[@"data"]];
            completion(model,YES,json[@"msg"]);
        }else{
            completion(nil,false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 收藏文章 网络请求
#define kFavoriteUrl @"Collection/favoritePost"
#define kCancelFavorUrl @"Collection/deleFavoritePost"
- (void)postFavoriteArticleWithTid:(NSString *)tid
                        isFavorite:(BOOL)isFavorite
                       completion:(void(^)(BOOL isSucc ,NSString *statusInfo))completion
{
    NSString *url = isFavorite ? kCancelFavorUrl : kFavoriteUrl;
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"tid"] = tid;
 
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
           
            completion(YES,[json[@"data"][@"reward"][@"is_reward"] boolValue] ? json[@"data"][@"reward"][@"money"] : nil);
        }else{
            completion(NO,json[@"msg"]);
        }
    }];
}

#pragma mark: - 上传头像 网络请求
- (void)postAvatorWithImage:(UIImage *)image
                 completion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"UserCenter/uploadUserAvatars";
    
    //图像
    NSData *imgData1 = nil;
    imgData1 =UIImageJPEGRepresentation(image,1);
    if ([imgData1 length]/1024<=100) {
        imgData1 =UIImageJPEGRepresentation(image,1);
        
    }else{
        
        imgData1 =UIImageJPEGRepresentation([self compressImage:image toByte:100*1024],0.5);
    }
    
  
    [self uploadWithUrlString:url
                         data:imgData1
                         name:@"user_avatar"
                       params:nil
                   completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        // 成功过
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,json[@"msg"]);
        }else{
            completion(NO,json[@"msg"]);
        }
    }];

}

#pragma mark: - 压缩图像
- (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength {
    
    // Compress by quality
    CGFloat compression = 1;
    NSData *data = UIImageJPEGRepresentation(image, compression);
    
    
    if (data.length < maxLength) return image;
    
    CGFloat max = 1;
    CGFloat min = 0;
    for (int i = 0; i < 6; ++i) {
        compression = (max + min) / 2;
        data = UIImageJPEGRepresentation(image, compression);
        if (data.length < maxLength * 0.9) {
            min = compression;
        } else if (data.length > maxLength) {
            max = compression;
        } else {
            break;
        }
    }
    
    UIImage *resultImage = [UIImage imageWithData:data];
    
    if (data.length < maxLength)
        
        return resultImage;
    
    // Compress by size
    NSUInteger lastDataLength = 0;
    while (data.length > maxLength && data.length != lastDataLength) {
        lastDataLength = data.length;
        CGFloat ratio = (CGFloat)maxLength / data.length;
        CGSize size = CGSizeMake((NSUInteger)(resultImage.size.width * sqrtf(ratio)),
                                 (NSUInteger)(resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank
        UIGraphicsBeginImageContext(size);
        [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
        resultImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        data = UIImageJPEGRepresentation(resultImage, compression);
        
    }
    
    return resultImage;
}
#pragma mark: - 获取验证码 网络请求
- (void)requestVerifyCodeWithMobile:(NSString *)mobile
                               type:(NSString *)type
                          timestamp:(NSString *)timestamp
                               sign:(NSString *)sign
                        completion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"Mobile/post";
    
    NSDictionary *param = @{@"mobile":mobile,
                            @"type":type,
                            @"timestamp":timestamp,
                            @"sign":sign
                            };

    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        // 成功过
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,json[@"data"][@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
        
        
    }];
}

#pragma mark: - 获取accessToken
- (void)requestAccessWithSignature:(NSString *)signature
                         device_id:(NSString *)device_id
                          rand_str:(NSString *)rand_str
                         timestamp:(NSString *)timestamp
                        completion:(void(^)(BOOL isSucc, NSString *error))completion
{
    NSString *url = @"BuildToken/getAccessToken";
    NSDictionary *parem = @{@"app_id":kApp_ID,
                            @"signature":signature,
                            @"device_id":device_id,
                            @"rand_str":rand_str,
                            @"timestamp":timestamp
                            };
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:parem
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            self.account.accessToken = json[@"data"][@"access_token"];
            completion(isSuccess,nil);
        }else{
            completion(false,json[@"msg"]);
        }
       
    }];
}

#pragma mark: - 获取个人信息 网络请求
- (void)requestUserInfoWithCompletion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"UserCenter/getUserInfo";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            [self.account yy_modelSetWithJSON:json[@"data"]];
            completion(isSuccess,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 更改手机号 网络请求
- (void)requestChangeMoblie:(NSString *)mobile
                 code:(NSString *)code
                 completion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"UserCenter/updatePhone";
    
    NSDictionary *param = @{@"mobile":mobile,
                            @"code":code
                            };
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 关注列表 / 作者列表 网络请求
#define kFollowListUrl @"UserCenter/getFollowList"
#define kAuthorListUrl @"UserCenter/authorList"
- (void)requestFollowListWithIsAuthorList:(BOOL)isAuthorList paged:(int)paged completion:(void(^)(YTFollowAuthorModel *model ,BOOL isSucc ,NSString *error))completion
{
    NSString *url = isAuthorList ? kAuthorListUrl : kFollowListUrl;
    
    NSDictionary *param = @{@"page":@(paged),
                            @"page_size":@(10)
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            YTFollowAuthorModel *model = [YTFollowAuthorModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,nil);
        }else{
            completion(nil,isSuccess,json[@"msg"]);
        }
    }];
}

#pragma mark: - 意见反馈 网络请求
- (void)postFeedBackWithContent:(NSString *)content
                     completion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"Home/feedBack";
    
    NSDictionary *param = @{@"content":content};
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 发表评论 网络请求
- (void)postCommentWithPostID:(NSString *)post_id
                      content:(NSString *)content
                   completion:(void(^)(BOOL isSucc, NSString *statusInfo))completion
{
    NSString *url = @"Home/publishComment";
    
    NSMutableDictionary *paraM = [NSMutableDictionary dictionary];
    paraM[@"post_id"] = post_id;
    paraM[@"content"] = content;

    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:paraM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        // 成功过
        if ([json[@"code"] intValue] == kSuccCode) {
            NSString *msg = [json[@"data"][@"reward"][@"is_reward"] boolValue] ? json[@"data"][@"reward"][@"money"] : nil;
            completion(YES,msg);
        }else{
            completion(false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 加入我们 网络请求
- (void)requestJoinUsWithCompletion:(void(^)(NSDictionary *dict, NSString *error))completion
{
    NSString *url = @"InvitingFriends/contactus";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        // 失败
        if (!isSuccess) {
            completion(nil,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json[@"data"],nil);
        }else{
            completion(nil,json[@"msg"]);
        }
        
        
    }];
}

#pragma mark: - 以太星球 网络请求
- (void)requestWithBallDataWithCompletion:(void(^)(YTEtaiModel *model, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"GetDig/getUserDigInfo";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            YTEtaiModel *model = [YTEtaiModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
        

    }];
}

#pragma mark: - 收取矿石 网络请求
- (void)requestETAIWithEid:(NSString *)eid
                completion:(void(^)(id json, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"GetDig/addUserEtaiNum";
    
    NSDictionary *param = @{@"eid":eid};
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力....");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json,isSuccess,nil);
        }else{
            completion(json,false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 以太星域排行榜 网络请求
- (void)requestWithRankListWithTypes:(NSString *)types
                           page_size:(NSString *)page_size
                          completion:(void(^)(NSArray<YTRankModel *> *rankList, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"GetDig/getTotalEtaiRank";
    
    NSDictionary *param = @{@"types":types,
                            @"page_size":page_size
                            };
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            NSArray *list = [NSArray yy_modelArrayWithClass:[YTRankModel class] json:json[@"data"]];
            completion(list,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
    
}

#pragma mark: - 以太护照 网络请求
- (void)requestWithETAIInfoWithCompletion:(void(^)(YTETAIPorpertyModel *model, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/etaiPassport";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
           
            YTETAIPorpertyModel *model = [YTETAIPorpertyModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
       
    }];
}
#pragma mark: - 微信登录绑带手机号 网络请求
- (void)requestBindPhoneWithWechat_uuid:(NSString *)wechat_uuid
                                  phone:(NSString *)phone
                                   code:(NSString *)code
                             completion:(void(^)(BOOL isSucc ,NSString *error))completion
{
    NSString *url = @"Com/wechatBindPhone";
    
    NSDictionary *param = @{@"wechat_uuid":wechat_uuid,
                            @"phone":phone,
                            @"code":code
                            };
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力...");
            return ;
        }
        
        // 成功
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSNumber *isPass = self.account.isPass;
            NSString *accessToken = self.account.accessToken;
            
            self.account = [YTUserAccount yy_modelWithJSON:json[@"data"]];
            self.account.isPass = isPass;
            self.account.accessToken = accessToken;
            [[self requestSerializer] setValue:self.account.auth forHTTPHeaderField:@"user-token"];
            [self.account saveUserAccount];
            completion(YES,json[@"msg"]);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 用户是否签到 网络请求
- (void)requestUserIsSiginWithCompletion:(void(^)(BOOL isSucc,BOOL isSign))completion
{
    NSString *url = @"UserCenter/checkUserIsSign";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,false);
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(isSuccess,[json[@"data"][@"issign"] boolValue]);
        }else{
            completion(isSuccess,false);
        }

    }];
}

#pragma mark: - 微信登录成功 网络请求
- (void)requestWechatLoginWithWechat_uuid:(NSString *)wechat_uuid
                               completion:(void(^)(BOOL isSucc ,BOOL isBindMoblie,NSString *error))completion
{
    NSString *url = @"Com/loginByWechat";
    
    NSDictionary *param = @{@"wechat_uuid":wechat_uuid};
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,false,@"网络有问题...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode || [json[@"code"] intValue] == -666) {
            if (([json[@"code"] intValue] == kSuccCode)) {
                NSNumber *isPass = self.account.isPass;
                NSString *accessToken = self.account.accessToken;
                
                self.account = [YTUserAccount yy_modelWithJSON:json[@"data"]];
                self.account.isPass = isPass;
                self.account.accessToken = accessToken;
                [[self requestSerializer] setValue:self.account.auth forHTTPHeaderField:@"user-token"];
                [self.account saveUserAccount];
            }
            completion(isSuccess,([json[@"code"] intValue] == kSuccCode),nil);
        }else{
            completion(false,false,json[@"msg"]);
        }
    }];
}


#pragma mark: - 开学季首页（答题个人信息）
- (void)requestUserInfoOfQuestion
{
    NSString *url = @"v1/TestQuestions/getUserTestInfo";
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            return ;
        }
        NSLog(@"%@",json);
        if ([json[@"code"] intValue] == kSuccCode) {
            
        }else{
            
        }
    }];
}

#pragma mark: - 检测
- (void)requestIsPassCompletion:(void(^)(BOOL isSucc,BOOL isPass))completion
{
    NSString *url = @"Test/checkIstrue";
    
    [self.requestSerializer setValue:nil forHTTPHeaderField:@"access-token"];
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        [self.requestSerializer setValue:self.account.accessToken forHTTPHeaderField:@"access-token"];
        if (!isSuccess) {
            completion(isSuccess,false);
            return ;
        }
        
        if ([json[@"data"][@"version"] intValue] == kSuccCode) {
            
            if ([json[@"data"][@"is_true"] intValue] == kSuccCode) {
                completion(isSuccess,YES);
            }else{
                completion(isSuccess,false);
            }
        }else{
            completion(isSuccess,YES);
        }
        
    }];
}

#pragma mark: - 星币明细 网络请求
- (void)requestEtAILogListWithPaged:(int)paged
                          page_size:(int)page_size
                         completion:(void(^)(YTETAILogModel *model,BOOL isSucc,NSString *error))completion
{
    NSString *url = @"Search/getIntegralLog";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"paged"] = @(paged);
    dictM[@"page_size"] = @(page_size);
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            YTETAILogModel *model = [YTETAILogModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 地址管理 网络请求
#define kWalletAddr @"v1/UsersCenter/walletAddr" // 钱包地址
#define kCollectAddr @"v1/UsersCenter/collectAddr" // 收货地址
- (void)requestAddressIsAddress:(BOOL)isAddress completion:(void(^)(NSArray *list, BOOL isSucc, NSString *error))completion
{
    NSString *url = isAddress ? kCollectAddr : kWalletAddr;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:nil
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            
            NSArray *list = [NSArray yy_modelArrayWithClass:isAddress ? [YTCollectAddrModel class] : [YTWalletAddrModel class] json:json[@"data"]];
            completion(list,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
}


#pragma mark: - 设为默认地址 网络请求
- (void)uploadDefaultAddrWithID:(NSString *)ID
                     completion:(void(^)(BOOL isSucc,NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/setDefaultAddr";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"id"] = ID;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力");
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,nil);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 新增/编辑收货地址
- (void)addOrEditeCollectAddrWithCollect_id:(NSString *)collect_id
                               collect_name:(NSString *)collect_name
                                      phone:(NSString *)phone
                                   province:(NSString *)province
                                       city:(NSString *)city
                                     county:(NSString *)county
                                       addr:(NSString *)addr
                                 completion:(void(^)(BOOL isSucc,NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/editCollect";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"collect_id"] = collect_id;
    dictM[@"collect_name"] = collect_name;
    dictM[@"phone"] = phone;
    dictM[@"province"] = province;
    dictM[@"city"] = city;
    dictM[@"county"] = county;
    dictM[@"addr"] = addr;
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(false,@"网络不给力");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,nil);
        }else{
            completion(false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 收货地址信息 网络请求
- (void)requestCollectAddrInfoWithID:(NSString *)ID
                          completion:(void(^)(id json, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/getCollectInfo";
    NSDictionary *param = @{@"id":ID};
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:param
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json[@"data"],isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 新增/编辑钱包
- (void)requestAddOrEditeWalletAddrWithName:(NSString *)name
                                       addr:(NSString *)addr
                                 product_id:(NSString *)product_id
                                  wallet_id:(NSString *)wallet_id
                             completion:(void(^)(BOOL isSucc,NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/editWallet";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"name"] = name;
    dictM[@"addr"] = addr;
    dictM[@"product_id"] = product_id;
    dictM[@"wallet_id"] = wallet_id;
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,nil);
        }else{
            completion(false,json[@"msg"]);
        }
    }];
}

#pragma mark: - 产品列表 1为虚拟币 2为其他
- (void)requestGetProductListWithType:(NSString *)type
                           completion:(void(^)(NSArray *list, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/getProductList";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"type"] = type;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json[@"data"],YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 钱包信息 网络请求
- (void)requestGetWalletInfoWithID:(NSString *)ID
                        completion:(void(^)(id json, BOOL isSucc, NSString *error))completion
{
    NSString *url = @"v1/UsersCenter/getWalletInfo";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"id"] = ID;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(json[@"data"],YES,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }
    }];
    
}

#pragma mark: - 查看作者所发表的文章 网络请求
- (void)requestAuthorArticleWithUserID:(NSString *)user_id
                             page_size:(NSString *)page_size
                            menu_order:(NSString *)menu_order
                               maxtime:(NSString *)maxtime
                               mintime:(NSString *)mintime
                            completion:(void(^)(YTAuthorPostArticleModel *model,BOOL isSucc, NSString *error))completion
{
    
    NSString *url = @"Home/getPersonalArticle";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"user_id"] = user_id;
    dictM[@"page_size"] = page_size;
    dictM[@"menu_order"] = menu_order;
    dictM[@"maxtime"] = maxtime;
    dictM[@"mintime"] = mintime;
    
    NSString *time = [NSString getNowTime];
    dictM[@"time"] = time;
    dictM[@"sign"] = [[NSString stringWithFormat:@"%@%@",kGetVerifiCodeKey,time] md5];

    [self.requestSerializer setValue:self.account.accessToken forHTTPHeaderField:@"access-token"];
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,isSuccess,@"网络不给力...");
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            YTAuthorPostArticleModel *model = [YTAuthorPostArticleModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,nil);
        }else{
            completion(nil,false,json[@"msg"]);
        }

    }];
}

#pragma mark: - 删除收货地址/删除钱包地址
#define kDelCollectAddrUrl @"v1/UsersCenter/collectDel"
#define kDelWalletAddrUrl @"v1/UsersCenter/walletDel"
- (void)requestDeleteAddrWithIsWallet:(BOOL)isWallet
                                   ID:(NSString *)ID
                                    completion:(void(^)(BOOL isSucc,NSString *error))completion
{
    NSString *url = isWallet ? kDelWalletAddrUrl : kDelCollectAddrUrl;
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    isWallet ? [dictM setValue:ID forKey:@"wallet_id"] : [dictM setValue:ID forKey:@"collect_id"];
    
    [self requestWithMethod:MethodPost
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(isSuccess,@"网络不给力...");
            return ;
        }
        if ([json[@"code"] intValue] == kSuccCode) {
            completion(YES,nil);
        }else{
            completion(false,json[@"msg"]);
        }
        
    }];
}

#pragma mark: - 用户关注的作者所发布的文章
- (void)requestFocusAuthorArticleWithPage_size:(NSString *)page_size
                                    menu_order:(NSString *)menu_order
                                       maxtime:(NSString *)maxtime
                                       mintime:(NSString *)mintime
                                    completion:(void(^)(YTHomeMainModel *model,BOOL isSucc, NSString *error))completion
{
    NSString *url = @"Home/getFocusPeopleArticle";
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"page_size"] = page_size;
    dictM[@"menu_order"] = menu_order;
    dictM[@"maxtime"] = maxtime;
    dictM[@"mintime"] = mintime;
    
    [self requestWithMethod:MethodGet
                  UrlString:url
                     params:dictM.copy
                 completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            completion(nil,false,@"网络不给力...");
            return ;
        }
        
        if ([json[@"code"] intValue] == kSuccCode) {
            YTHomeMainModel *model = [YTHomeMainModel yy_modelWithJSON:json[@"data"]];
            completion(model,isSuccess,false);
        }else{
            completion(nil,false,json[@"msg"]);
        }
        
    }];
}

@end
